package com.woniu.serviceverificationcode.controller;

import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.response.NumberCodeResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@RestController
@Slf4j
public class verifycodeController {


    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size ){

        // 生成6位数字大小写字母 验证码
        System.out.println("生成验证码");
        String sourceChar = "1234567890";
        char[] m = sourceChar.toCharArray();
        String resultString = "";
        for (int i=0;i<size;i++){
            char temp = m[new Random().nextInt(10)];

            resultString = resultString + temp;

        }
        // 定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(resultString);

        return ResponseResult.success(response);
    }
}
